// TOWN SCRIPT
//    Town 6: Small Cave

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

set_char_dialogue_pic(8,518,0);

if(get_flag(6,0) == 0) {
	message_dialog("You enter this small cave, and squint through the darkness ahead. You can't make out much from here, but you can just about make out some sort of building to the west.","There are also two sources of light - one, a camp fire south of the building, and another just in front of you, that you can't quite identify.");
	message_dialog("This must be the cave Mayor Stone told you about. Tovas should be inside - hopefully he does know something about Laurina.","");
	set_flag(6,0,1);
}

set_terrain(28,14,0);

if(get_flag(6,2) == 1) {
	set_terrain(23,13,0);
	set_terrain(23,14,0);
	set_terrain(23,15,0);
}

if(get_flag(6,3) == 1) {
	erase_char(6);
	erase_char(7);
	erase_char(8);
}

set_char_dialogue_pic(8,518,0);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.

		if (get_ran(1,0,100) < 5)
			text_bubble_on_char(8,"Where is it?");
		if (get_ran(1,0,100) < 5)
			text_bubble_on_char(8,"I wonder...");

break;

//Shelves
beginstate 10;
	print_str("You find nothing of value.");
break;

//House Greeting
beginstate 11;
	if(get_flag(6,1) == 0) {
		message_dialog("You enter this small, humble building. The ceiling is low, and it is slightly chilly inside. A few bookshelves line the walls, and a low bed is gathering dust in the corner...","Apart from a smattering of papers on the table, there is no sign that this place is inhabited... Tovas must spend all of his time reading.");
		set_flag(6,1,1);
	}
break;

//Tripped wire
beginstate 12;

	if(get_flag(6,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"There is a thin red beam of light spanning the entrance to this small cave. It appears to be magical - it's not giving off any heat, and it doesn't have any visible source.",0);
		add_dialog_str(1,"Unfortunately, you can't progress into this cave without stepping through it. Do you?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");
		if(run_dialog(1) == 2) {
			message_dialog("You stay on the side of caution - you have no idea what may happen to you if you step into the beam.","Still, you won't be able to explore here unless you do go through it.");
			block_entry(1);
			end();
		} else {
			message_dialog("You step forward...","");
			
			//start cutscene. Oy. next scenario I'm just gonna let you 
			//butcher everything that moves I think. 
			
			//Summary - Intro to Tovas. He tells you he knows more about monster, 
			//Rox enters, tells you to speak to mayor. 
			
			march_party(23,14);
			pause(3 * get_flag(250,5));
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			message_dialog("...and nothing seems to happen. The beam wavers slightly, and then disappears completely, in a haze of sparks. You wait a moment more. Nothing happens. Then suddenly, you hear a noise to the west...","");
			
			//kill beam, add nice sparkles.
			
			set_terrain(23,13,0);
			set_terrain(23,14,0);
			set_terrain(23,15,0);
			play_sound(-171);
			set_character_facing(1000,2);
			force_instant_terrain_redraw();
			
			
			//and now lets introduce Tovas...
			
			force_view_center(19,14);
			activate_hidden_group(1);
			force_instant_terrain_redraw();	
			
			text_bubble_on_char(6,"Who on Earth...?");
			
			relocate_character(6,15,13);
			force_instant_terrain_redraw();	
			pause(5 * get_flag(250,5));
			
			relocate_character(6,15,14);
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//he's done his little walk, now to face the party
			
			set_character_facing(6,6);
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"Who are you?");
			force_instant_terrain_redraw();	
			pause(5 * get_flag(250,5));
			
			relocate_character(6,16,14);
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			pause(3 * get_flag(250,5));
			
			relocate_character(6,17,14);
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"And more to the point...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...what are you doing here?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			pause(10 * get_flag(250,5));
			
			//he stops here, lets you speak. 
			
			message_dialog("After a moment that seems to span the ages, you speak...","");
					
			text_bubble_on_char(0,"Erm...");
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"Yes?");
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			message_dialog("The man asks, puzzled. You think you detect the slightest smile on his face...","");
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			if(party_size() > 1) {
				text_bubble_on_char(0,"We're looking for...");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,5));
			
				erase_text_bubbles();
				force_instant_terrain_redraw();	
			} else {
				text_bubble_on_char(0,"I'm looking for...");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,5));
			
				erase_text_bubbles();
				force_instant_terrain_redraw();	
			}
			
			text_bubble_on_char(0,"...Mayor Stone's daughter.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"That is to say,");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"Laurina.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			if(party_size() > 1) {
				text_bubble_on_char(0,"We heard you might know where she is.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,5));
			
				erase_text_bubbles();
				force_instant_terrain_redraw();	
			} else {
				text_bubble_on_char(0,"I heard you might know where she is.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,5));
			
				erase_text_bubbles();
				force_instant_terrain_redraw();	
			}
			
			
			//dialog while he speaks
			
			message_dialog("The man tilts his head slightly to the left, and looks at you properly, apparently sizing you up. For what reason, you aren't sure.","Then, after a moment, he speaks.");
						
			reset_dialog();
			add_dialog_str(0,"_Firstly, I assume you're assuming I am Tovas?_ You nod. _Right. Well, you shouldn't - the world is never as straight-forward as you percieve it to be._ He grins.",0);
			add_dialog_str(1,"_But, I am the person you seek. And sadly, I can't help you. I had heard of Laurina's disappearance, but I don't know where she is. Now..._ he begins,",0);
			run_dialog(1);
			
			text_bubble_on_char(6,"If that's all?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"I'm a busy man...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//you butt in
			
			text_bubble_on_char(0,"Actually, no. It's not.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));pause(15);
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//dialog cus he's not happy
			
			message_dialog("Tovas frowns for a moment, but then, almost immediately smiles. _Of course, anything to help your search. I'll answer your questions as best I can._","");
						
			text_bubble_on_char(0,"Okay...");
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"Why did you flee from Greenleaf?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"Surely, a magic-user...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"...such as yourself...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(0,"...would be a great asset right now?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//Answers questions
			
			message_dialog("Tovas nods. _Yes, I would. Which is why the monster attacked me. It came into my house at night, and attacked me. I managed to flee, and ran here.","");
			
			//no, you aren't, damn adventurers :p
			
			text_bubble_on_char(0,"What?!");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			message_dialog("Tovas nods.","");
			
			text_bubble_on_char(6,"Yes. I came here");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"to try and find out");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"exactly what we're dealing with.");
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"I had, back 'home'...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...discovered that the...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...monster wasn't a dumb creature...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...as we first thought.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
						
			text_bubble_on_char(6,"And having information...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...like that about it...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...made me the perfect target.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"So after it attacked,");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"I came here, and hid.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			message_dialog("He frowns.","");
			
			text_bubble_on_char(6,"And now I'll have to leave.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"If you could find me...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"..the monster might too.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"I'll have to see Stone...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(6,"...for telling you where I was.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//He gets ready to go. You've not learnt owt.
			
			message_dialog("Tovas sighs, and mutters something under his breath. Then, he turns to you. _I'm sure our paths will meet again. Fair well, adventurers. I wish you all the best._","And then, with a final word, and a flourish of his hands, Tovas disappears.");
			
			put_boom_on_char(6,3,0);
			run_animation_sound(-10);
			erase_char(6);
			force_instant_terrain_redraw();
			
			//set view back
			
			force_view_center(23,14);
			force_instant_terrain_redraw();
			
			message_dialog("You ponder over what was just said. Tovas knows about the _monster_, but said nothing to you about it.","Suddenly you hear something approaching from behind you. You spin around, and take defensive stances just inside the cave...");
			
			//Move party just inside cave
			
			relocate_character(0,22,13);
			relocate_character(1,22,15);
			relocate_character(2,21,13);
			relocate_character(3,21,15);
			
			//Make them face east, draw weapons, play sound
			
			set_character_facing(1000,6);
			set_character_pose(1000,2);
			play_sound(-18);
			pause(6 * get_flag(250,5));
			force_instant_terrain_redraw();
			
			message_dialog("Whoever, or whatever, you heard approaching continues trudging on... You grip your weapons as the possibility that you were followed plays on your mind.","");
			
			//A few footsteps...
			
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
						
			message_dialog("You strain your eyes against the bright daylight to the east, and see a shadow moving towards you. It enters the room, and raises its hand...","");
			
			//Intro to Rox		
			
			force_view_center(27,14);
			force_instant_terrain_redraw();
			
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
			play_sound(50);
			pause(3 * get_flag(250,5));
						
			activate_hidden_group(2);
			force_instant_terrain_redraw();	
			
			message_dialog("You blink a few times, and relax slightly. It's Roxy, the girl you saw in Mayor Stone's office back in Greenleaf. She pauses a moment, and squints at you.","Clearly recognising you, she smiles, and approaches...");
			
			//Make her talk... is this dragging?? :p
			
			set_character_pose(1000,0);			
			relocate_character(7,27,14);
			force_instant_terrain_redraw();
			
			pause(3 * get_flag(250,5));
			relocate_character(7,26,14);
			text_bubble_on_char(7,"Well, well...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
				
			relocate_character(7,25,14);
			text_bubble_on_char(7,"...here before me, huh?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//Party interject
			
			text_bubble_on_char(0,"Yes, and you'll never guess...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			//She continues...
			
			message_dialog("You tell Roxy about your conversation with Tovas, missing out no details. When you've finished, she stands still, and chews her bottom lip a little.","Finally, after a moment, she begins to speak:");
			
			text_bubble_on_char(7,"Umm. Well, I don't know.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"From what you said,");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"he seemed reluctant...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...to tell you anything of...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...any value.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			message_dialog("She pauses again.","");
			
			pause(3 * get_flag(250,5));
			
			text_bubble_on_char(7,"I'm going to have a...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...look around. You can...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...either come and speak...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...to me, or go speak...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"...to Mayor Stone.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			text_bubble_on_char(7,"Your choice.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			
			erase_char(7);
			activate_hidden_group(3);
			force_instant_terrain_redraw();	
			
			message_dialog("With that, Roxy walks past you, and into the hut Tovas came from. You should probably speak to her before you go, although you should also speak to Mayor Stone as soon as possible.","For now though, talking to Roxy seems more reasonable - she may not be here for much longer.");		
			
			//set center closer to party	
			
			force_view_center(22,13);
			force_instant_terrain_redraw();
			
			//finally, set flag so that all this is over. 
		
			set_flag(6,2,1);
			
			//block entry. 
			
			block_entry(1);
		
			//and switch this quest off
			
			toggle_quest(3,0);
		}
}
break;

beginstate 13;
	if((get_flag(6,2) == 1) && (get_flag(6,3) == 0)) {
		message_dialog("You make to leave, but you realise you haven't spoken to Roxy yet. You should probably check in with her before going - she may have found something crucial to your quest.","");
		block_entry(1);
	}
break;

beginstate 14;
	message_dialog("You look at this sign, but can't make out what it says. The language is beyond archaic. However, it looks newly engraved. Tovas must have made this plaque.","");
break;